// ignore_for_file: non_constant_identifier_names, prefer_const_constructors, constant_identifier_names

import 'package:flutter/material.dart';
import 'assets.dart';
import 'package:flutter_kit_dsp/flutter_kit_dsp.dart';

Color hexToColor(String hexString) {
  final buffer = StringBuffer();
  if (hexString.length == 6 || hexString.length == 7) buffer.write('ff');
  buffer.write(hexString.replaceFirst('#', ''));
  return Color(int.parse(buffer.toString(), radix: 16));
}

void log(String message) {
  final timestamp = DateTime.now().toString();
  print('[$timestamp]:  $message');
}

///初始化连接按钮
Widget initConnectList(
    List<GroupModel> list, void Function(GroupModel) onChange) {
  return Row(
    mainAxisAlignment: MainAxisAlignment.center,
    mainAxisSize: MainAxisSize.max,
    children: list.map(($0) {
      return Expanded(
          child: IconButton(
              splashColor: Colors.transparent,
              highlightColor: Colors.transparent,
              onPressed: () {
                ///取消选中group
                if ($0.select) {
                  $0.select = false;

                  ///如果这时候，没有任何ch选中，
                  if (globalModel.select_ch_list.isEmpty ||
                      globalModel.select_ch_list.first.name == '') {
                    $0.ch1!.select = true;
                  }
                }

                ///选中group
                else {
                  for (var group in list) {
                    group.select = group.name == $0.name;
                  }
                }

                onChange($0);
              },
              padding: EdgeInsets.zero, //,
              iconSize: 20,
              icon: Image.asset(
                  $0.select ? assets.connect : assets.connect_dis)));
    }).toList(),
  );
}
